package cn.lijiajia3515.cairo.auth.modules.department;

import cn.lijiajia3515.cairo.core.page.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public interface DepartmentInterface {

	@PostMapping("/find")
	List<Department> find(@RequestBody FindDepartmentParam param);

	default Map<String, Department> findMap(FindDepartmentParam param) {
		return find(param).stream().collect(Collectors.toMap(Department::getId, x -> x));
	}

	@PostMapping("/find/page")
	Page<Department> findPage(@RequestBody FindDepartmentParam param);

	@PostMapping("/find/tree")
	List<DepartmentTreeNode> findTree();

	@PostMapping("/find/id/{id}")
	List<PathDepartment> findId(@PathVariable(name = "id") String id);

	@PostMapping("/find/ancestor")
	List<PathDepartment> findAncestor(@RequestBody FindDepartmentParam param);

	@PostMapping("/save")
	Department save(@RequestBody SaveDepartmentParam param);

	@PutMapping("/modify")
	Department modify(@RequestBody ModifyDepartmentParam param);

	@DeleteMapping("/delete")
	List<Department> delete(@RequestBody DeleteDepartmentParam param);

}
